<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        li{
            margin-bottom: 10px;
        }
    </style>
</head>

<body>
    <div id="app">
        <ul>
            <li v-for="item in list" :key="item.id">
                {{item.num}}
                <button @click="del(item.id)">删除</button>
            </li>
        </ul>

        <button @click="add">生成</button>
    </div>
</body>
<script src="../vue.js"></script>
<script>
    const app = new Vue({
        el: '#app',
        data: {
            list: []
        },
        methods: {
            add() {
                let obj = {
                    id: this.list.length + 1,
                    num: ~~(Math.random() * 21)
                }
                this.list.push(obj)
            },
            del(id) {
                this.list = this.list.filter(item => item.id !== id)
            }
        }
    })
</script>

</html>